From 7e53c9445d1d023677dd7c64024e1a31cad721f0 Mon Sep 17 00:00:00 2001
From: Masatake Iwasaki <iwasakims@apache.org>
Date: Mon, 11 Nov 2019 10:51:12 +0900
Subject: [PATCH] HADOOP-15685. Build fails (hadoop pipes) on newer Linux envs
 (like Fedora 28).

---
 hadoop-tools/hadoop-pipes/src/CMakeLists.txt | 41 ++++++++++++++++++--
 1 file changed, 37 insertions(+), 4 deletions(-)

diff --git a/hadoop-tools/hadoop-pipes/src/CMakeLists.txt b/hadoop-tools/hadoop-pipes/src/CMakeLists.txt
index ff660bfafce..d48db527582 100644
--- a/hadoop-tools/hadoop-pipes/src/CMakeLists.txt
+++ b/hadoop-tools/hadoop-pipes/src/CMakeLists.txt
@@ -22,6 +22,19 @@ list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/../../../hadoop-common-project
 include(HadoopCommon)
 
 find_package(OpenSSL REQUIRED)
+find_package(PkgConfig QUIET)
+pkg_check_modules(LIBTIRPC libtirpc)
+
+find_path(TIRPC_INCLUDE_DIRS
+    NAMES netconfig.h
+    PATH_SUFFIXES tirpc
+    HINTS ${LIBTIRPC_INCLUDE_DIRS}
+)
+
+find_library(TIRPC_LIBRARIES
+    NAMES tirpc
+    HINTS ${LIBTIRPC_LIBRARY_DIRS}
+)
 
 include_directories(
     main/native/utils/api
@@ -30,21 +43,41 @@ include_directories(
     ${OPENSSL_INCLUDE_DIR}
 )
 
+if(LIBTIRPC_FOUND)
+    include_directories(${TIRPC_INCLUDE_DIRS})
+endif()
+
 # Example programs
 add_executable(wordcount-simple main/native/examples/impl/wordcount-simple.cc)
-target_link_libraries(wordcount-simple hadooppipes hadooputils)
+if(LIBTIRPC_FOUND)
+    target_link_libraries(wordcount-simple hadooppipes hadooputils tirpc)
+else()
+    target_link_libraries(wordcount-simple hadooppipes hadooputils)
+endif()
 hadoop_output_directory(wordcount-simple examples)
 
 add_executable(wordcount-part main/native/examples/impl/wordcount-part.cc)
-target_link_libraries(wordcount-part hadooppipes hadooputils)
+if(LIBTIRPC_FOUND)
+    target_link_libraries(wordcount-part hadooppipes hadooputils tirpc)
+else()
+    target_link_libraries(wordcount-part hadooppipes hadooputils)
+endif()
 hadoop_output_directory(wordcount-part examples)
 
 add_executable(wordcount-nopipe main/native/examples/impl/wordcount-nopipe.cc)
-target_link_libraries(wordcount-nopipe hadooppipes hadooputils)
+if(LIBTIRPC_FOUND)
+    target_link_libraries(wordcount-nopipe hadooppipes hadooputils tirpc)
+else()
+    target_link_libraries(wordcount-nopipe hadooppipes hadooputils)
+endif()
 hadoop_output_directory(wordcount-nopipe examples)
 
 add_executable(pipes-sort main/native/examples/impl/sort.cc)
-target_link_libraries(pipes-sort hadooppipes hadooputils)
+if(LIBTIRPC_FOUND)
+    target_link_libraries(pipes-sort hadooppipes hadooputils tirpc)
+else()
+    target_link_libraries(pipes-sort hadooppipes hadooputils)
+endif()
 hadoop_output_directory(pipes-sort examples)
 
 add_library(hadooputils STATIC
-- 
2.18.1

